package com.ewanghuiju.app.ui.shopmail.activity;

import android.graphics.Paint;
import android.view.Gravity;
import android.view.View;
import android.view.animation.Animation;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.ewanghuiju.app.R;
import com.ewanghuiju.app.base.BaseActivity;
import com.ewanghuiju.app.base.contract.shopmail.MailShopDetailsContract;
import com.ewanghuiju.app.model.bean.response.PintuanHotTuijianResponBean;
import com.ewanghuiju.app.presenter.shopmail.MailShopDetailsPresenter;
import com.ewanghuiju.app.test.bean.PintuanHomeBannerBean;
import com.ewanghuiju.app.test.bean.TestBean;
import com.ewanghuiju.app.ui.pintuan.adapter.PintuanHotTuijianAdapter;
import com.ewanghuiju.app.util.ToastUtil;
import com.ewanghuiju.app.util.nodoubleclick.AntiShake;
import com.ewanghuiju.app.widget.popupwindow.ShareShopPopup;
import com.ewanghuiju.app.widget.popupwindow.ToGroupleadPopup;
import com.gyf.immersionbar.ImmersionBar;
import com.makeramen.roundedimageview.RoundedImageView;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.stx.xhb.androidx.XBanner;

import java.util.ArrayList;
import java.util.List;

import androidx.cardview.widget.CardView;
import androidx.core.widget.NestedScrollView;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author sj  qq:751943509
 * @class 优惠券商品详情
 * @time 2020/2/18
 */
public class MailShopDetailsActivity extends BaseActivity<MailShopDetailsPresenter> implements MailShopDetailsContract.View {

    @BindView(R.id.roll_view_pager)
    XBanner rollViewPager;
    @BindView(R.id.nsv_view)
    NestedScrollView nsvView;
    @BindView(R.id.now_price)
    TextView nowPrice;
    @BindView(R.id.yuan_price)
    TextView yuanPrice;
    @BindView(R.id.tv_sale)
    TextView tvSale;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.layout_top)
    LinearLayout layoutTop;
    @BindView(R.id.riv_head_1)
    RoundedImageView rivHead1;
    @BindView(R.id.tv_pingjia_name_1)
    TextView tvPingjiaName1;
    @BindView(R.id.tv_pingjia_time_1)
    TextView tvPingjiaTime1;
    @BindView(R.id.tv_pingjia_text1)
    TextView tvPingjiaText1;
    @BindView(R.id.riv_head_2)
    RoundedImageView rivHead2;
    @BindView(R.id.tv_pingjia_name_2)
    TextView tvPingjiaName2;
    @BindView(R.id.tv_pingjia_time_2)
    TextView tvPingjiaTime2;
    @BindView(R.id.tv_pingjia_text2)
    TextView tvPingjiaText2;
    @BindView(R.id.card_view_pingjia)
    CardView cardViewPingjia;
    @BindView(R.id.recyclerView_rmtj)
    RecyclerView recyclerViewRmtj;
    @BindView(R.id.iv_collect)
    ImageView ivCollect;
    @BindView(R.id.tv_share_zhuan)
    TextView tvShareZhuan;
    @BindView(R.id.tv_kaituan_zhuan)
    TextView tvKaituanZhuan;
    @BindView(R.id.refreshLayout)
    SmartRefreshLayout refreshLayout;
//    @BindView(R.id.pageView)
//    PageGridView pageView;


    private PintuanHotTuijianAdapter hotAdapter;

    @Override
    protected void initInject() {
        getActivityComponent().inject(this);
    }

    @Override
    protected int getLayout() {
        return R.layout.activity_mail_shop_details;
    }

    @Override
    protected void initEventAndData() {
        yuanPrice.setText("￥5699");
        yuanPrice.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG); // 设置中划线并加清晰
        initBanner();
        initHotTuijian();
//        initPageGridView();
    }

    @Override
    protected void intSmartRefreshLayout() {
//        super.intSmartRefreshLayout();
        refreshLayout.setEnableLoadMore(false);
    }

    /**
     * 加载banner
     */
    public void initBanner() {
        //测试数据  测试bean
        List<PintuanHomeBannerBean> bannerList = new ArrayList<>();
        PintuanHomeBannerBean bean = new PintuanHomeBannerBean();
        bean.setResId(R.mipmap.bg_splash);
        bannerList.add(bean);
        bean = new PintuanHomeBannerBean();
        bean.setResId(R.mipmap.bg_splash);
        bannerList.add(bean);
        bean = new PintuanHomeBannerBean();
        bean.setResId(R.mipmap.bg_splash);
        bannerList.add(bean);
        rollViewPager.setBannerData(bannerList);
        //加载广告图片
        rollViewPager.loadImage(new XBanner.XBannerAdapter() {
            @Override
            public void loadBanner(XBanner banner, Object model, View view, int position) {
                Glide.with(mContext).load(R.mipmap.bg_splash).skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into((ImageView) view);
            }
        });
    }

    /***
     * 热门推荐
     */
    private void initHotTuijian() {
        List<PintuanHotTuijianResponBean> pintuanHotTuijianResponBeans = TestBean.getPintuanHotTuijianResponBeanList(1);
        hotAdapter = new PintuanHotTuijianAdapter(R.layout.item_pintuan_tuijian_hot);
        recyclerViewRmtj.setLayoutManager(new GridLayoutManager(mContext, 2));
        hotAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                ToastUtil.show(position + "");
            }
        });
        recyclerViewRmtj.setAdapter(hotAdapter);
        hotAdapter.addData(pintuanHotTuijianResponBeans);
        hotAdapter.notifyDataSetChanged();
    }


//    private void initPageGridView() {
//        List<PintuanHotTuijianResponBean> pintuanHotTuijianResponBeans = TestBean.getPintuanHotTuijianResponBeanList();
//        pageView.setData(pintuanHotTuijianResponBeans);
//        pageView.setOnItemClickListener(new PageGridView.OnItemClickListener() {
//            @Override
//            public void onItemClick(int position) {
//                ToastUtil.show("" + position);
//            }
//        });
//    }


    ToGroupleadPopup toGroupleadPopup;
    //    PintuanFuwuPopup pintuanFuwuPopup;
//    PintuanYoufeiPopup pintuanYoufeiPopup;
    ShareShopPopup shareShopPopup;

    @OnClick({R.id.tv_kaituan_zhuan, R.id.tv_share_zhuan, R.id.iv_share_shop})
    public void doClick(View view) {
        if (AntiShake.check(view.getId())) {    //判断是否多次点击
            return;
        }
        switch (view.getId()) {
            case R.id.tv_kaituan_zhuan:
                //开团赚
                if (toGroupleadPopup == null) {
                    toGroupleadPopup = new ToGroupleadPopup(mContext);
                }
                toGroupleadPopup.setPopupGravity(Gravity.BOTTOM);
                toGroupleadPopup.showPopupWindow();
                break;
            case R.id.tv_share_zhuan:
                //分享赚

                break;
//            case R.id.iv_fuwu_more:
//                if (pintuanFuwuPopup == null) {
//                    pintuanFuwuPopup = new PintuanFuwuPopup(mContext);
//                }
//                pintuanFuwuPopup.setPopupGravity(Gravity.BOTTOM);
//                pintuanFuwuPopup.showPopupWindow();
//                break;
//            case R.id.iv_youfei_more:
//                if (pintuanYoufeiPopup == null) {
//                    pintuanYoufeiPopup = new PintuanYoufeiPopup(mContext);
//                }
//                pintuanYoufeiPopup.setPopupGravity(Gravity.BOTTOM);
//                pintuanYoufeiPopup.showPopupWindow();
//                break;
            case R.id.iv_share_shop:
                //分享商品
                if (shareShopPopup == null) {
                    shareShopPopup = new ShareShopPopup(mContext, MailShopDetailsActivity.this, "", null);
                }
                float fromX = 0;
                float fromY = 1f;
                float toX = 0;
                float toY = 0;
                Animation showAnimation = createTranslateAnimation(fromX, toX, fromY, toY);
                Animation dismissAnimation = createTranslateAnimation(toX, fromX, toY, fromY);
                shareShopPopup.setShowAnimation(showAnimation);
                shareShopPopup.setDismissAnimation(dismissAnimation);
                shareShopPopup.setImgUrl("https://img.zcool.cn/community/0131ae5e12a8eca80121651859ec77.jpg@2o.jpg");
                shareShopPopup.setPopupGravity(Gravity.BOTTOM);
                shareShopPopup.showPopupWindow();
                break;
            default:
                break;
        }
    }

    @Override
    public void showContent(String list) {

    }

    @Override
    public void showMoreContent(String list) {

    }

    @Override
    protected void initImmersionBar() {
        super.initImmersionBar();
        ImmersionBar.with(this).titleBar(R.id.toolbar)
                .statusBarDarkFont(true)
                .init();
    }

}
